% This script load the USGS Dst values 1999 to 2009
dst_1999 = load('/home/mnair/projects/realtime_mag/USGS_1999.txt');
dst_2000 = load('/home/mnair/projects/realtime_mag/USGS_2000.txt');
dst_2001 = load('/home/mnair/projects/realtime_mag/USGS_2001.txt');
dst_2002 = load('/home/mnair/projects/realtime_mag/USGS_2002.txt');
dst_2003 = load('/home/mnair/projects/realtime_mag/USGS_2003.txt');
dst_2004 = load('/home/mnair/projects/realtime_mag/USGS_2004.txt');
dst_2005 = load('/home/mnair/projects/realtime_mag/USGS_2005.txt');
dst_2006 = load('/home/mnair/projects/realtime_mag/USGS_2006.txt');
dst_2007 = load('/home/mnair/projects/realtime_mag/USGS_2007.txt');
dst_2008 = load('/home/mnair/projects/realtime_mag/USGS_2008.txt');
dst_2009 = load('/home/mnair/projects/realtime_mag/USGS_2009.txt');

dst_1999_2009 = [dst_1999(:,3); dst_2000(:,3) ; dst_2001(:,3); dst_2002(:,3); dst_2003(:,3); dst_2004(:,3); dst_2005(:,3); dst_2006(:,3); dst_2007(:,3); dst_2008(:,3); zeros([1,1440])'; dst_2009(:,3);  zeros([1,1440])'];


dst_2010_2012 = [zeros([1,275*1440]) DstMinData(1:end-1440)];
dst_1999_20121026 = [dst_1999_2009' dst_2010_2012];

% write these values to a binary file
% break them into three so the file will be less than 10 MB
fid = fopen('/home/mnair/projects/realtime_mag/Dst_Min_1999_20121026_part1.bin','wb');
fwrite(fid,int32(dst_min(1:2500000)),'int32');
fclose all
fid = fopen('/home/mnair/projects/realtime_mag/Dst_Min_1999_20121026_part2.bin','wb');
fwrite(fid,int32(dst_min(2500001:5000000)),'int32');
fclose all
fid = fopen('/home/mnair/projects/realtime_mag/Dst_Min_1999_20121026_part3.bin','wb');
fwrite(fid,int32(dst_min(5000001:end)),'int32');
fclose all

% create a time stamp (unix time)

dst_fday = (( datenum(1999,1,1,0,0,0): 1/1440: datenum(2012,10,25,23,59,0) ) - datenum(1970,1,1))*24*3600;



% write these values to a binary file
% break them into three so the file will be less than 10 MB
fid = fopen('/home/mnair/projects/realtime_mag/Dst_Min_Time_1999_20121026_part1.bin','wb');
fwrite(fid,int32(dst_fday(1:2500000)),'int32');
fclose all
fid = fopen('/home/mnair/projects/realtime_mag/Dst_Min_Time_1999_20121026_part2.bin','wb');
fwrite(fid,int32(dst_fday(2500001:5000000)),'int32');
fclose all
fid = fopen('/home/mnair/projects/realtime_mag/Dst_Min_Time_1999_20121026_part3.bin','wb');
fwrite(fid,int32(dst_fday(5000001:end)),'int32');
fclose all

%% No trying to read these values
% I was trying to see whether these data files are better than the online
% USGS Dst values. They both have some unremoved Sq components.

% create a time stamp (unix time)

dst_fday =  datenum(1999,1,1,0,0,0): 1/1440: datenum(2012,10,25,23,59,0);

% declare data array

dst_min = zeros(1,length(dst_fday));
% read from binary file
% 

fid = fopen('/nfs/satmag_work/mnair/projects/realtime_mag/Dst_Min_1999_20121026_part1.bin','rb');
dst_min(1:2500000) = fread(fid,2500000,'int32');
fclose all
fid = fopen('/nfs/satmag_work/mnair/projects/realtime_mag/Dst_Min_1999_20121026_part2.bin','rb');
dst_min(2500001:5000000) = fread(fid,2500000,'int32');
fclose all
fid = fopen('/nfs/satmag_work/mnair/projects/realtime_mag/Dst_Min_1999_20121026_part3.bin','rb');
dst_min(5000001:length(dst_min)) = fread(fid,length(dst_min)-5000000 ,'int32');
fclose all




% write these values to a binary file
% break them into three so the file will be less than 10 MB
fid = fopen('/home/mnair/projects/realtime_mag/Dst_Min_Time_1999_20121026_part1.bin','wb');
fwrite(fid,int32(dst_fday(1:2500000)),'int32');
fclose all
fid = fopen('/home/mnair/projects/realtime_mag/Dst_Min_Time_1999_20121026_part2.bin','wb');
fwrite(fid,int32(dst_fday(2500001:5000000)),'int32');
fclose all
fid = fopen('/home/mnair/projects/realtime_mag/Dst_Min_Time_1999_20121026_part3.bin','wb');
fwrite(fid,int32(dst_fday(5000001:end)),'int32');
fclose all



